<template>
  <div class="asset-inr">
    <div class="header">
      <div class="back" @click="handleBack">
        <span class="back-arrow">﹤</span>
      </div>
      <div class="title">资产信息</div>
    </div>

    <div class="balance-card">
      <div class="currency-row">
        <img
          src="https://coinlist000.s3.ap-east-1.amazonaws.com/INR.png"
          alt="INR"
          class="currency-icon"
        />
        <span class="currency-name">INR</span>
      </div>
      <div class="balance-grid">
        <div class="balance-item">
          <div class="balance-value blue">{{ unserInfo.availableBalance }}</div>
          <div class="balance-label">可用余额</div>
        </div>
        <div class="balance-item">
          <div class="balance-value blue">{{ unserInfo.frozenBalance }}</div>
          <div class="balance-label">冻结</div>
        </div>
        <div class="balance-item">
          <div class="balance-value blue">{{ unserInfo.inrBalance }}</div>
          <div class="balance-label">总资金</div>
        </div>
      </div>
    </div>

    <div class="transaction-list">
      <div
        class="transaction-item"
        v-for="(item, index) in transactions"
        :key="index"
      >
        <div class="left-section">
          <div class="account-name">货币账户</div>
          <div class="tx-tag profit-tag" v-if="item.actualProfit>=0">期货盈利</div>
          <div class="tx-tag buy-tag" v-else>期货亏损</div>
        </div>
        <div class="right-section">
          <div class="tx-amount profit-amount" v-if="item.actualProfit>=0">+{{ item.actualProfit&&item.actualProfit.toFixed(2) }} INR</div>
          <div class="tx-amount buy-amount" v-else>{{ item.actualProfit&&item.actualProfit.toFixed(2) }} INR</div>
          <div class="tx-time">2025-04-14 20:38</div>
        </div>
      </div>
      <div class="load-more"></div>
    </div>
  </div>
</template>

<script setup name="AssetsInr">
import { ref } from "vue";
import { AssetsApi } from "@/api/assets.ts";
import { UserApi } from '../api/user.api';
import { useRouter } from "vue-router";
const router = useRouter();
const handleBack = () => {
  router.go(-1); // Go back to the previous page
};
const transactions = ref([]);
const init = () => {
  AssetsApi.getTradeOrders({
    page: 0,
    size: 10,
    status:""
  }).then((res) => {
    if (res.code == 200) {
      transactions.value = res.data.records;
    }
  });
};

const unserInfo = ref({});
const getInfo = () => {
  UserApi.wallet().then(res => {
    if (res.code === 200) {
      // Handle wallet data here
      unserInfo.value = res.data;
    }
  });
};
init();
getInfo();
</script>

<style scoped>
.asset-inr {
  height: 100vh;
  background: #121212;
}

.header {
  display: flex;
  align-items: center;
  padding: 12px;
  background: #1e1e1e;
  border-bottom: 1px solid #333333;
}

.back {
  position: absolute;
  left: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.back-arrow {
  font-size: 18px;
  color: #fff;
  font-weight: 400;
  transform: scale(1.3, 1.6);
  display: inline-block;
  line-height: 1;
}

.title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  color: #fff;
}

.balance-card {
  background: #1e1e1e;
  margin: 15px;
  padding: 15px;
  border-radius: 4px;
  box-shadow: 0 1px 3px #0003;
}

.currency-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 15px;
}

.currency-icon {
  width: 24px;
  height: 24px;
  filter: brightness(1.2);
}

.currency-name {
  font-size: 16px;
  font-weight: 500;
  color: #fff;
}

.balance-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
}

.balance-value {
  font-size: 14px;
  margin-bottom: 4px;
}

.balance-value.blue {
  color: #4254ef;
}

.balance-label {
  font-size: 12px;
  color: #b0b0b0;
}

.transaction-list {
  margin: 15px 0;
}

.transaction-item {
  margin: 10px 15px;
  padding: 15px;
  background: #1e1e1e;
  border: 1px solid rgba(64, 84, 239, 0.3);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 0 0 1px #4054ef4d;
}

.left-section {
  display: flex;
  flex-direction: column;
}

.account-name {
  font-size: 14px;
  color: #fff;
  margin-bottom: 8px;
}

.tx-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  min-width: 60px;
  text-align: center;
}

.profit-tag {
  background: #4caf50;
  color: #fff;
}
.buy-tag {
  background: #ef5350;
  color: #fff;
}
.right-section {
  text-align: right;
}

.tx-amount {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}
.buy-amount {
  color: #ff5f57;
}
.profit-amount {
  color: #4ade80;
}

.tx-time {
  font-size: 12px;
  color: #b0b0b0;
  text-align: right;
}

.load-more {
  text-align: center;
  padding: 15px;
  color: #b0b0b0;
  font-size: 14px;
}
</style>
